home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 February / EnigmA AMIGA RUN 15 (1997)(G.R. Edizioni)(IT)[!][issue 1997-02][PLANET CD V].iso / progs / editor / frexxed / fpl / assemble.fpl < prev    next >
Text File  |  1995-07-18  |  5KB  |  220 lines

  1. // Assemble.FPL by Bjorn Reese <breese@imada.ou.dk>
  2.  
  3. // Assemble
  4.  
  5. export void Asm_Assemble(void)
  6. {
  7.     string file = ReadInfo("file_name");
  8.     string command = sprintf("CD %s\n%s >%s %s %s",
  9.         ReadInfo("file_path"),
  10.         ReadInfo("_Assembler"),
  11.         ReadInfo("_Errorfile"),
  12.         ReadInfo("_Asm_opt"),
  13.         file);
  14.  
  15.     SaveChanges();
  16.     Status(0, sprintf("Assembling %s ...", file));
  17.     System(command);
  18.     Asm_LoadErrors();
  19. }
  20.  
  21. // Assemble with debug informations
  22.  
  23. export void Asm_AssembleDebug(void)
  24. {
  25.     string file = ReadInfo("file_name");
  26.     string command = sprintf("CD %s\n%s >%s %s %s %s",
  27.         ReadInfo("file_path"),
  28.         ReadInfo("_Assembler"),
  29.         ReadInfo("_Errorfile"),
  30.         ReadInfo("_Asm_opt"),
  31.         file,
  32.         ReadInfo("_Asm_debug_opt"));
  33.  
  34.     SaveChanges();
  35.     Status(0, sprintf("Assembling %s ...", file));
  36.     System(command);
  37.     Asm_LoadErrors();
  38. }
  39.  
  40. // Make
  41.  
  42. export void Asm_Make(void)
  43. {
  44.     string command = sprintf("CD %s\n%s >%s",
  45.         ReadInfo("file_path"),
  46.         ReadInfo("_Make"),
  47.         ReadInfo("_Errorfile"));
  48.  
  49.     SaveChanges();
  50.     Status(0, "Make...");
  51.     System(command);
  52.     Status(0, "");
  53.     Asm_LoadErrors();
  54. }
  55.  
  56. // Launch debugger
  57.  
  58. export void Asm_Debug(void)
  59. {
  60.     System(sprintf("CD %s\nRun >NIL: %s %s", ReadInfo("file_path"), ReadInfo("_Debugger"), stripExt(ReadInfo("file_name"))));
  61. }
  62.  
  63. // Execute program
  64.  
  65. export void Asm_Execute(void)
  66. {
  67.     int ret;
  68.  
  69.     Status(0, "Executing...");
  70.     if (ret = System(sprintf("CD %s\n%s", ReadInfo("file_path"), stripExt(ReadInfo("file_name")))))
  71.         ReturnStatus(sprintf("Error code: %ld", ret));
  72. }
  73.  
  74. // Load and filter errors
  75.  
  76. export void Asm_LoadErrors(void)
  77. {
  78.     string errFile = ReadInfo("_Errorfile");
  79.     string convFile = joinstr(errFile, ".list");
  80.     string command = sprintf("%s <%s >%s %s", ReadInfo("_Filter"), errFile, convFile, ReadInfo("file_name"));
  81.  
  82.     errLine = 0;
  83.     System(command);
  84.     LoadBlock(convFile);
  85.     if (strlen(GetBlockLine(0))) {
  86.         maxLines = ReadInfo("lines", errorID)-1;
  87.         Asm_NextError();
  88.     } else
  89.         ReturnStatus("No Errors");
  90. }
  91.  
  92. // Jump to error
  93.  
  94. export void Asm_NextError(void)
  95. {
  96.     if (++errLine > maxLines) {
  97.         errLine = maxLines+1;
  98.         DisplayBeep();
  99.         ReturnStatus("Last error.");
  100.     } else
  101.         JumpError();
  102. }
  103.  
  104. export void Asm_PrevError(void)
  105. {
  106.     if (--errLine < 1) {
  107.         errLine = 0;
  108.         DisplayBeep();
  109.         ReturnStatus("First error.");
  110.     } else
  111.         JumpError();
  112. }
  113.  
  114. void JumpError(void)
  115. {
  116.     string thisLine=GetBlockLine(errLine);
  117.     string fileName, errorType, errorMsg;
  118.     int posCnt=0, posEnd, lineNum;
  119.  
  120.     while (thisLine[posCnt++]!='>');
  121.     fileName = substr(thisLine, 1, posCnt-2);
  122.     while (Isspace(thisLine[posCnt++]));
  123.     lineNum = atoi(substr(thisLine, posCnt-1, 16));
  124.     while (!Isspace(thisLine[posCnt++]));
  125.     errorType = substr(thisLine, posCnt++, 1);
  126.     while (thisLine[posCnt++]!='<');
  127.     for(posEnd=posCnt; thisLine[posEnd++]!='>'; );
  128.     errorMsg = substr(thisLine, posCnt-1, posEnd-posCnt+1);
  129.  
  130.     if (strcmp(fileName, ReadInfo("file_name"))) {
  131.         Request(sprintf("(%s) Line %ld %s\n\nFile: %s", errorType, lineNum, errorMsg, fileName), "Error", "OK");
  132.         ReturnStatus("");
  133.     } else {
  134.         GotoLine(lineNum);
  135.         CenterView();
  136.         InverseLine();
  137.         ReturnStatus(sprintf("(%s) Line %ld  %s", errorType, lineNum, errorMsg));
  138.     }
  139. }
  140.  
  141. int LoadBlock(string fileName)
  142. {
  143.     if (errorID) {
  144.         Kill(errorID);
  145.         errorID = 0;
  146.     }
  147.     errorID = BlockCreate("Error List");
  148.     return (StringToBlock(LoadString(fileName), errorID));
  149. }
  150.  
  151. string GetBlockLine(int lineNum)
  152. {
  153.     int currentID = GetBufferID();
  154.     string lineStr;
  155.  
  156.     CurrentBuffer(errorID);
  157.     lineStr = GetLine(lineNum);
  158.     CurrentBuffer(currentID);
  159.     return (lineStr);
  160. }
  161.  
  162. // Strip Extension
  163.  
  164. string stripExt(string name) {return(substr(name, 0, strstr(name, ".")));}
  165.  
  166. // Change Settings
  167.  
  168. export void Asm_Settings(void)
  169. {
  170.     string assembler = ReadInfo("_Assembler"), asmopt = ReadInfo("_Asm_opt"),
  171.         asmdopt = ReadInfo("_Asm_debug_opt"), filter = ReadInfo("_Filter"),
  172.         debugger = ReadInfo("_Debugger"), make = ReadInfo("_Make"),
  173.         errfile = ReadInfo("_Errorfile");
  174.  
  175.     if (RequestWindow("Assembler Settings",
  176.         "Assembler", "S", &assembler,
  177.         "Assembler Options", "S", &asmopt,
  178.         "Assembler Debug Options", "S", &asmdopt,
  179.         "Filter", "S", &filter,
  180.         "Debugger", "S", &debugger,
  181.         "Make", "S", &make,
  182.         "Error File", "S", &errfile))
  183.     {
  184.         SetInfo(0, "_Assembler", assembler, "_Asm_opt", asmopt, "_Asm_debug_opt", asmdopt,
  185.             "_Filter", filter, "_Debugger", debugger, "_Make", make, "_Errorfile", errfile);
  186.     }
  187. }
  188.  
  189.  
  190. // Globals
  191.  
  192. export int errorID = 0, errLine = 0;
  193. export int maxLines = 0;
  194.  
  195. // Infos
  196.  
  197. ConstructInfo("_Assembler", "", "", "GSHW", "", 0, 0, "ASM:Barfly/basm");
  198. ConstructInfo("_Asm_opt", "", "", "GSHW", "", 0, 0);
  199. ConstructInfo("_Asm_debug_opt", "", "", "GSHW", "", 0, 0, "-sa -sf -s1 -dDEBUG=1");
  200. ConstructInfo("_Filter", "", "", "GSHW", "", 0, 0, "bin/Barfly2Msg");
  201. ConstructInfo("_Debugger", "", "", "GSHW", "", 0, 0, "ASM:Barfly/bdebug");
  202. ConstructInfo("_Make" , "", "", "GSHW", "", 0, 0, "sc:c/smake -s");
  203. ConstructInfo("_Errorfile", "", "", "GSHW", "", 0, 0, "T:Errorlist");
  204.  
  205. // Menu shortcuts
  206.  
  207. MenuAdd("t", "Assembler");
  208.     MenuAdd("i", "Assemble", "Asm_Assemble();", "Control a");
  209.     MenuAdd("i", "Assemble w/debug", "Asm_AssembleDebug();", "Control A");
  210.     MenuAdd("i", "Make", "Asm_Make();", "Control m");
  211.     MenuAdd("i", "Debug", "Asm_Debug();", "Control d");
  212.     MenuAdd("i", "Execute", "Asm_Execute();", "Control x");
  213.     MenuAdd("i", "---");
  214.     MenuAdd("i", "Load Errors", "Asm_LoadErrors();");
  215.     MenuAdd("i", "Next Error", "Asm_NextError();", "Control n");
  216.     MenuAdd("i", "Previous Error", "Asm_PrevError();", "Control p");
  217.     MenuAdd("i", "---");
  218.     MenuAdd("i", "Settings...", "Asm_Settings();");
  219. MenuBuild();
  220.